package com.kobeliu.entity;

/**
 * @Author: Kobe_Liu
 * @Date: 2021/12/21 9:37
 */
public class Demo_87_No1154 {

    public static void main(String[] args) {

        System.out.println(dayOfYear("2019-03-09"));
    }

    public static int dayOfYear(String date)
    {
        int year = 0;
        int mouth = 0;
        int day = 0;
        int sum = 0;
        int[] nums = {31,29,31,30,31,30,31,31,30,31,30,31};
        if(date.contains("-")){
            String[] strs = date.trim().split("-");
            year = Integer.parseInt(strs[0]);
            mouth = Integer.parseInt(strs[1]);
            day = Integer.parseInt(strs[2]);
        }
        if(year!=0 && mouth!=0 && day!=0){
            if(year%4==0 && year%100 != 0 || year%400==0){
                //闰年
                for(int i=0;i<mouth-1;i++){
                    sum += nums[i];
                }
                sum += day;
            }else{
                if(mouth>2){
                    for(int i=0;i<mouth-1;i++){
                        sum += nums[i];
                    }
                    sum += day-1;
                }else if(mouth==2){
                    sum = 31+day;
                }else{
                    sum = day;
                }
            }
        }
        return sum;
    }


}
